// stk_para.cpp
//
#include "stk_para.h"
#include <boost/lexical_cast.hpp>

using namespace std;
using boost::lexical_cast;
using boost::bad_lexical_cast;

namespace quigon
{

typedef Serie<string, string> Para_Serie;

// This maybe used on YL lidar, too.
bool STK_Para::load(const string& filename)
{
	try
	{
		// notice it's not possible to
		// Para_Serie str_para(filename), because of ambiguous overloaded function.
		Para_Serie str_para;
		str_para.load(filename);

		lidar_name = str_para["lidar_name"] ;
		size = lexical_cast<size_t>(str_para["size"]);
		bin_size = lexical_cast<double>(str_para["bin_size"]);
		start_value = lexical_cast<double>(str_para["start_value"]);
		station_height = lexical_cast<double>(str_para["station_height"]);
		station_lat = lexical_cast<double>(str_para["station_lat"]);
		station_lon = lexical_cast<double>(str_para["station_lon"]);

		zero_meter_index = lexical_cast<size_t>(str_para["zero_meter_index"]);
		first_usable_index = lexical_cast<size_t>(str_para["first_usable_index"]);
		lambda = lexical_cast<double>(str_para["lambda"]);
		rho_n = lexical_cast<double>(str_para["rho_n"]);
		lidar_ratio.load(str_para["lidar_ratio_file"]) ;
		lidar_constant.load(str_para["lidar_constant_file"]) ;
		elev_angle.load(str_para["elev_angle_file"]) ;

		size_t size = lexical_cast<size_t> (str_para["size"]);
		double start_value = lexical_cast<double> (str_para["start_value"]);
		double bin_size = lexical_cast<double> (str_para["bin_size"]);

		distance.resize(size);
		distance_i.clear();  // it's a map. may contain old data.
		for (size_t i = 0; i < size; ++i)
		{
			distance[i] = start_value + bin_size * i;
			distance_i.add_entry(start_value + bin_size * i, i);
		}

		overlap.load(str_para["overlap_file"]);
		afterpulse.load(str_para["afterpulse_file"]) ;

		data_path = str_para["data_path"];
		file_ext = str_para["file_ext"];


		return true;
	}
	catch (...)
	{
		func_err("load_stk_para", filename);
		throw;
	}
}

}

